package com.mt.vsphere.core.util;


import com.mt.vsphere.core.exceptions.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
public class TokenUtil {

//    @Autowired
//    public UserCache userCache;
//
//    @Autowired
//    public BackUserDao backUserDao;
//
//    @Autowired
//    public NewsUserDao userDao;

    public boolean verifyAdmin(String token){
        try {
            if (!verifyBackUser(token)){
                return false;
            }
        }catch (BaseException e){
            return false;
        }
        return true;
    }

    private boolean verifyBackUser(String token){
//        BackUser backUser = backUserDao.findByToken(token);
//        return backUser != null;
        return true;
    }

    public boolean verifyUser(String token, HttpServletRequest servletRequest){
//        try {
//            NewsUser newsUser = userCache.verifyToken(token);
//            servletRequest.setAttribute("userinfo",newsUser);
//        }catch (BaseException e){
//            return false;
//        }
        return true;
    }

    public boolean verifyWriter(String token, HttpServletRequest servletRequest){
//        try {
//            NewsUser newsUser = userCache.verifyToken(token);
//            if (newsUser.getType() == UserType.Normal.num){
//                return false;
//            }
//            servletRequest.setAttribute("userinfo",newsUser);
//        }catch (BaseException e){
//            return false;
//        }
        return true;
    }


}


